<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<title>操作管理</title>
<body>
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',border:false" style="height: 40px;">
			<form id="schForm">
				<table>
					<tr>
						<td class="fm_lab">操作代码:</td>
						<td><input name="operateCodeSch" type="text" class="easyui-validatebox"></td>
						<td class="fm_lab">操作名称:</td>
						<td><input name="operateNameSch" type="text" class="easyui-validatebox"></td>
						<td><a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="crud.search();">查询</a></td>
					</tr>
				</table>
			</form>
		</div>

		<div id="toolbar">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="crud.add()">添加操作类型</a>
		</div>

		<div data-options="region:'center',border:false">
			<table id="dg"></table>
		</div>

		<div id="dlg" class="easyui-dialog" style="width: 320px; height: 150px;" closed="true" modal="true" buttons="#dlg-buttons">
			<form id="fm" method="post">
				<table class="table">
					<tbody>
						<tr>
							<th>操作代码:</th>
							<td><input name="operateCode" type="text" class="easyui-validatebox" required="true"></td>
						</tr>
						<tr>
							<th>操作名称:</th>
							<td><input name="operateName" type="text" class="easyui-validatebox" required="true"></td>
						</tr>
					</tbody>
				</table>
			</form>
		</div>

		<div id="dlg-buttons">
			<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="crud.save(); return false;">保存</a> <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="crud.closeDlg(); return false;">取消</a>
		</div>

		<div id="dlgDel" class="easyui-dialog" style="width: 360px; height: 280px; padding: 10px" closed="true" modal="true" title="删除操作" buttons="#dlgdlgDel-buttons">
			<div style="color: red; padding-bottom: 5px;">该操作正在被使用，无法删除。</div>
			<div id="delGrid"></div>
		</div>
		<div id="dlgdlgDel-buttons">
			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="$('#dlgDel').dialog('close'); return false;">关闭</a>
		</div>
	</div>

	<script type="text/javascript">
		var that = this;
		var $dlgDel = $('#dlgDel');
		var crud = Crud.create({
			pk : 'operateCode',
			listUrl : ctx + 'listRSysOperate.do',
			addUrl : ctx + 'addRSysOperate.do',
			updateUrl : ctx + 'updateRSysOperate.do',
			delUrl : ctx + 'delRSysOperate.do',
			dlgId : 'dlg',
			formId : 'fm',
			gridId : 'dg',
			searchFormId : 'schForm'
		});

		var buttons = [ {
			text : '修改',
			onclick : function(row) {
				crud.update(row);
			}
		}, {
			text : '删除',
			onclick : function(row) {
				del(row);
			}
		} ];

		var appendOpts = {
			rownumbers : true,
			pageSize : 50
		};

		crud.buildGrid([ {
			field : 'operateCode',
			title : '操作代码'
		}, {
			field : 'operateName',
			title : '操作名称'
		}, crud.createOperColumn(buttons) ], appendOpts);

		$('#delGrid').datagrid({
			columns : [ [ {
				field : 'funcName',
				title : '使用地方',
				width : 200,
				formatter : function(val, rowData) {
					return rowData.resName + "-" + val;
				}
			} ] ],
			height : 150,
			fitColumns : true,
			striped : true
		})

		function del(row) {
			if (row) {
				delRow = row;
				Action.post(ctx + 'listOperateUse.do', row, function(r) {
					if (r.operateCodeUsed) {
						var title = '删除[<span style="color:red;">' + row.operateCode + '</span>]'
						$('#delGrid').datagrid('loadData', r.operateCodeUsedList);
						$('#dlgDel').dialog('setTitle', title).dialog('open');
					} else {
						crud.del(row);
					}
				})
			}
		}

		function viewOperateUse() {
			$('#delGridCont').show();
		}
	</script>
</body>